#include <bits/stdc++.h>
using namespace std;

int q;
long v[100005],d[100005],p[100005],a[100005];
bool b[100005]={1};

int main()
{
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	cin >> q;
	for(int k = 1;k <= q;k++)
	{

		
		int ans1 = 0 , ans2 = 0;
		int n,m,ll,vv;
		cin >> n >> m >> ll >> vv;
		for(int i = 1;i <= n;i++)
		{
			cin >> d[i] >> v[i] >> a[i];
		}
		for(int i = 1;i <= m;i++)
		{
			cin >> p[i];
		}
		
		for(int i = 1;i <= n;i++)
		{
			if( v[i] > vv && d[i] <= p[m])
			{
				ans1++;
			}
			
		}
		
		ans2 = m-1;
		if(ans1 == 0) ans2 = m;
		cout << ans1 << " " << ans2 << endl;
	}
	return 0;
}
